﻿<cfmodule template="../../tag/layout.cfm" bodyIsEasyUILayout="false">
<script type="text/javascript" charset="utf-8" src="assets/js/fwExtEasyUIvalidate.js"></script>
<cfscript>
	if( structKeyExists(rc, "id")  && rc.id > 0 ){
		id = rc.id;
	}else{
		id = 0;
	}
</cfscript>
<form method="post" class="form" name="form">
  <fieldset>
    <legend>基本信息</legend>
    <table class="table" width="100%">
      <tbody>
        <tr>
          <th>编号</th>
          <td><input name="id" readonly/></td>
          <th>登陆帐号</th>
          <td><input name="loginname" class="easyui-validatebox" data-options="required:true"/></td>
        </tr>

        <tr>
          <th>昵称</th>
          <td><input name="nickname" class="easyui-validatebox" data-options="required:true"/></td>
          <th>真实姓名</th>
          <td><input name="truename"/></td>
        </tr>

		<tr>
          <th>登陆密码</th>
          <td><input type="password" id="loginpassword"  name="loginpassword" class="easyui-validatebox" data-options="required:true"/></td>
          <th>支付密码</th>
          <td><input type="password" id="paypassword"  name="paypassword" class="easyui-validatebox" data-options="required:true"/></td>
        </tr>

        <tr>
          <th>性别</th>
          <td><input name="sex" type="radio" value="0" class="easyui-validatebox" validType="radio['form','sex']"/>女
          <input name="sex" type="radio" value="1" class="easyui-validatebox" validType="radio['form','sex']"/>男 </td>
          <th>出生日期</th>
          <td><input name="birthday" class="easyui-datebox"/></td>
        </tr>

        <tr>
          <th>收信邮箱</th>
          <td><input name="email" class="easyui-validatebox" data-options="validType:'email'"/> </td>
          <th>邮政编码</th>
          <td><input name="zip" class="easyui-validatebox" data-options="validType:'zip'" style="width:60px;"/></td>
        </tr>

 		<tr>
          <th>地区</th>
          <td colspan="3">
          	  <input type="hidden" id="location" name="location">
	 		  <input class="easyui-combobox" id="province" name="province" data-options="valueField:'id',textField:'text'" style="width:80px;">
	 		  <input class="easyui-combobox" id="city" name="city" data-options="valueField:'id',textField:'text'" style="width:80px;">
	 		  <input class="easyui-combobox" id="area" name="area" data-options="valueField:'id',textField:'text'" style="width:80px;">
          </td>
        </tr>

         <tr>
          <th>详细地址</th>
          <td colspan="3"><input name="address" style="width:430px;" /> </td>
        </tr>

        <tr>
          <th>手机</th>
          <td><input name="mobile" class="easyui-validatebox" data-options="validType:'mobile'"/> </td>
          <th>座机</th>
          <td><input name="phone" class="easyui-validatebox" data-options="validType:'phone'"/></td>
        </tr>
      </tbody>
    </table>
  </fieldset>
</form>

</cfmodule>

<script type="text/javascript">
	var closeDialog = function($dialog) {
		$dialog.dialog('destroy');
	}

	var submitNow = function($dialog, $grid, $pjq) {
		var url;
		if ($(':input[name="id"]').val().length > 0) {
			url = '?action=members.update'; //更新操作
		} else {
			url = '?action=members.save';	//新增操作
		}
//		console.log( fw.serializeObject($('form')) );
		$.post(url, fw.serializeObject($('form')), function(result) {
			if (result) {
				$grid.datagrid('reload');
				$dialog.dialog('destroy');
			}
		}, 'json');
	};

	var submitForm = function($dialog, $grid, $pjq) {

		var location = [];

		var province = $('#province').combobox('getValue');
		var city = $('#city').combobox('getValue');
		var area = $('#area').combobox('getValue');
		if(province.length>0){
			location[0] = province;
		}

		if(city.length>0){
			location[1] = city;
		}

		if(area.length>0){
			location[2] = area;
		}

		$('#location').val( location.toString());

		if ($('form').form('validate')) {
			submitNow($dialog, $grid, $pjq);
		}
	};

	//加载数据，初始进度条
	parent.$.messager.progress({
		text : '数据加载中....'
	});


	$(function(){
		$('#province').combobox('reload', '?action=category.getlistbytarget');
		$('#province').combobox({
			onSelect: function(param){
				$('#city').combobox('setValue','');
				$('#area').combobox('setValue','');
				$('#area').combobox('reload',{});
				$('#city').combobox('reload', '?action=category.getlistbytarget&id=' + param.id);
			}
		});
		$('#city').combobox({
			onSelect: function(param){
				$('#area').combobox('setValue','');
				$('#area').combobox('reload', '?action=category.getlistbytarget&id=' + param.id);
			}
		});

        $.ajax({
		    type: "POST",
		    url: "?action=members.get",
		    data: {
		        id:<cfoutput>#id#</cfoutput>
		    }
		}).done(function(result) {
			$('form').form('load', result);
			if(result!=false){
				province = result.location.split(',')[0];
				city = result.location.split(',')[1];
				area = result.location.split(',')[2];
				if(province>0){
					$('#province').combobox('setValue',province);
					if(city>0){
						$('#city').combobox('reload', '?action=category.getlistbytarget&id=' + province);
						$('#city').combobox('setValue',city);
						if(area>0){
							$('#area').combobox('reload', '?action=category.getlistbytarget&id=' + city);
							$('#area').combobox('setValue',area);
						}
					}
				}

			}
			parent.$.messager.progress('close');
		});

	})
</script>
